home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 6 / clmfeb85.zip / BENMRK.LTG < prev    next >
Text File  |  1988-07-25  |  5KB  |  265 lines

  1.  
  2.  
  3.                        The Deref Benchmark
  4.                         C Compiler Review
  5.                  February 1985 COMPUTER LANGUAGE
  6.  
  7.  
  8. /*
  9. **     deref.c -- benchmark program to examine the effeciency
  10. **  of pointer dereferencing
  11. */
  12.  
  13. #define LOOPS    50000      /* how many loops */
  14. #define BELL     7          /* ASCII bell character */
  15.  
  16. struct cptr1  {
  17.         char ********************ptr1;
  18.         };
  19.         
  20. main()
  21. {
  22. unsigned i;
  23. char yekdorb;
  24. struct cptr1 ********************pointer;
  25.  
  26.         printf("%u loops\n", LOOPS);
  27.         
  28.         for (i = 0; i <= LOOPS; i++)
  29.             yekdorb = ********************
  30.                 (********************pointer).ptr1;
  31.                         
  32.         printf("%cfinished\n", BELL);
  33.         exit(0);
  34. }
  35.  
  36.  
  37.  
  38.  
  39.                         The Fib Benchmark
  40.                        C Compiler Analysis
  41.                  February 1985 COMPUTER LANGUAGE
  42.  
  43.  
  44. /* Fibonacci Number Generator in C */
  45. #include "STDIO.H"
  46. #define NTIMES 10         /* number of times to computer Fibonacci value */
  47.  
  48. #define NUMBER 24         /* biggest that can be computed in 16 bits */
  49.  
  50.  
  51. void main()                /* compute Fibonacci value */
  52.     {
  53.     int i;
  54.     unsigned value, fib();
  55.  
  56.     printf("%d iterations:  ", NTIMES);
  57.     for (i = 1;  i <= NTIMES;  i++)
  58.         value = fib(NUMBER);
  59.     printf("Fibonacci(%d) = %u.\n", NUMBER, value);
  60.     exit(0);
  61.     }
  62.  
  63. unsigned fib(x)            /* compute Fibonacci number recursively */
  64. int x;
  65.     {
  66.  
  67.     if (x > 2)
  68.         return (fib(x - 1) + fib(x - 2));
  69.     else return (1);
  70.     }
  71.  
  72.  
  73.  
  74.  
  75.  
  76.                       The Matrix Benchmark
  77.                        C Compiler Analysis
  78.                  February 1985 COMPUTER LANGUAGE
  79.  
  80. /*
  81. ** Matrix.c -- a benchmark based on the matrix multiplication
  82. ** program given by Jerry Pournelle in Byte October 1982 p. 254.
  83. **
  84. ** Type conversions have been made explicit with casts. Array
  85. ** and loop indices now start at 0.
  86. */
  87.  
  88. #define M     20
  89. #define N     20
  90. #define BELL  7
  91.  
  92. char gup;
  93. double summ, a[M][N], b[N][M], c[M][M];
  94.  
  95. main()
  96. {
  97.  
  98.     summ = 0.0;
  99.     printf("Hit any character to start\n");
  100.     gup = getchar();
  101.     
  102.     filla();
  103.     printf("\nA filled\n");
  104.     fillb();
  105.     printf("\nB filled\n");
  106.     fillc();
  107.     printf("\nC filled\n");
  108.     
  109.     matmult();
  110.     printf("\nMultiplied\n");
  111.     summit();
  112.     
  113.     printf("The sum is: %20f\n", summ);
  114.     putchar(BELL);
  115. }
  116.  
  117. filla()
  118. {
  119. int i, j;
  120.  
  121.     for (i=0; i < M; i++)
  122.         for (j = 0; j < N; j++)
  123.             a[i][j] = (double) (i+1) + (j+1);
  124. }
  125.  
  126. fillb()
  127. {
  128. int i, j;
  129.  
  130.     for (i=0; i < N; i++)è        for (j = 0; j < M; j++)
  131.             b[i][j] = (double) (int) (((i+1) + (j+1)) / (j+1));
  132. }
  133.  
  134. fillc()
  135. {
  136. int i, j;
  137.  
  138.     for (i=0; i < M; i++)
  139.         for (j = 0; j < M; j++)
  140.             c[i][j] = (double) 0;
  141. }
  142.  
  143. matmult()
  144. {
  145. int i, j, k;
  146.  
  147.     for (i = 0; i < M; i++)
  148.         for (j = 0; j < N; j++)
  149.             for (k = 0; k < M; k++)
  150.                 c[i][j] = c[i][j] + a[i][k]*b[k][j];
  151. }
  152.  
  153. summit()
  154. {
  155. int i, j;
  156.  
  157.     for (i = 0; i < M; i++)
  158.         for (j = 0; j < M; j++)
  159.             summ = summ + c[i][j];
  160. }
  161.  
  162.  
  163.  
  164.  
  165.                  Sieve of Eratosthenes Benchmark
  166.                        C Compiler Analysis
  167.                  February 1985 COMPUTER LANGUAGE
  168.  
  169.  
  170. /* Eratosthenes Sieve Prime Number Program in C */
  171. #define TRUE    1
  172. #define FALSE    0
  173. #define SIZE    8190
  174.  
  175. char flags[SIZE+1];
  176.  
  177. main()
  178. {
  179. int i, prime, k, count, iter;
  180.  
  181.     printf("10 iterations.\n");
  182.     for (iter = 1; iter <= 10; iter++) {
  183.         count = 0;
  184.         for (i = 0; i <= SIZE; i++)
  185.             flags[i] = TRUE;
  186.         for (i = 0; i<= SIZE; i++) {
  187.             if (flags[i]) {
  188.                 prime = i + i + 3;
  189.                 for (k = i + prime; k <= SIZE; k += prime)
  190.                     flags[k] = FALSE;
  191.                 count++;
  192.             }
  193.         }
  194.     }
  195.     printf("%d %d\n", prime, count);
  196. }
  197.  
  198.  
  199.  
  200.  
  201.                        TRS Seive Benchmark
  202.                        C Compiler Analysis
  203.                  February 1985 COMPUTER LANGUAGE
  204.  
  205.  
  206. SIEVE listing used to test LC:
  207. /*  sieve test program for CLM C-compiler comparisons
  208.     Jim Kyle, 6 November 1984
  209.  */
  210. #include stdio/csh
  211. #define size 8190
  212.     char flags[8191];
  213. main()
  214. {
  215.     int i,prime,k,count,iter;
  216.     printf("Start\n");
  217.     for (iter=1; iter <= 10; iter++)  {
  218.         count = 0;
  219.         for (i=0; i <= size; i++)
  220.             flags[i] = TRUE;
  221.         for (i=0; i<= size; i++)      {
  222.             if (flags[i])    {
  223.                 prime = i + i + 3;
  224.                 for (k=i+prime; k <=size; k+=prime)
  225.                     flags[k] = FALSE;
  226.                 count++;
  227.             }
  228.         }
  229.     }
  230.     printf("\nFound %d; stop\n", count);
  231. }
  232. /* END OF PROGRAM */
  233.  
  234.  
  235.  
  236. MYSORT listing used to test LC:
  237. /*    mysort/ccc - integer sorting benchmark, LC */
  238. #include stdio/csh
  239. #define MAX 1000èint a[MAX], working, jump,i,j,tempo;
  240. main()
  241. {    printf("Initializing array\n");
  242.     for (i=0; i<MAX; ++i)
  243.         a[i] = i;
  244.     jump = MAX;
  245.     printf("Beginning to sort\n");
  246.     while (jump>0)    {
  247.         jump /= 2;
  248.         do    {
  249.             working=FALSE;
  250.             for (j=0; j<(MAX-jump);    ++j)    {
  251.                 i=j+jump;
  252.                 if (a[i] > a[j])    {
  253.                     working=TRUE;
  254.                     tempo=a[i];
  255.                     a[i]=a[j];
  256.                     a[j]=tempo;
  257.                 }
  258.             }
  259.         } while (working);
  260.     }
  261.     printf("Finished sorting\n");
  262.     for (i=0; i<MAX; ++i)
  263.         printf("%d ",a[i]);
  264. }
  265.